/**
 * 
 */
package com.yidu.commom;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Random;

/**
 * @author TaleShenHua
 * @date 2018年3月30日 上午10:14:55
 * @version 1.0
 */
public class PhoneSendTool {
	private static String operation = "/industrySMS/sendSMS";

	private static String accountSid = Config.ACCOUNT_SID;

	/**
	 * 验证码通知短信
	 */
	public static String execute(String phone) {
		Random rd = new Random();
		int ran = rd.nextInt(900000) + 100000;
		String smsContent = "【饱了么外卖】您的验证码为"+ran+"，请于3分钟内正确输入，如非本人操作，请忽略此短信。";
		String tmpSmsContent = null;
		try {
			tmpSmsContent = URLEncoder.encode(smsContent, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		String url = Config.BASE_URL + operation;
		String body = "accountSid=" + accountSid + "&to=" + phone + "&smsContent=" + tmpSmsContent
				+ HttpUtil.createCommonParam();

		// 提交请求
		String result = HttpUtil.post(url, body);
		System.out.println("result:" + System.lineSeparator() + result);
		return ""+ran;
	}
	
	/**
	 * 审核通过通知短信
	 */
	public static String auditPass(String phone) {
		Random rd = new Random();
		int ran = rd.nextInt(900000) + 100000;
		String smsContent = "【饱了么外卖】尊敬的"+phone+"用户，您的开店审核已通过，登录密码为"+ran+"，祝您开店大吉。";
		String tmpSmsContent = null;
		try {
			tmpSmsContent = URLEncoder.encode(smsContent, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		String url = Config.BASE_URL + operation;
		String body = "accountSid=" + accountSid + "&to=" + phone + "&smsContent=" + tmpSmsContent
				+ HttpUtil.createCommonParam();

		// 提交请求
		String result = HttpUtil.post(url, body);
		System.out.println("result:" + System.lineSeparator() + result);
		return ""+ran;
	}
	
	/**
	 * 审核通过通知短信
	 */
	public static String auditFail(String phone) {
		Random rd = new Random();
		int ran = rd.nextInt(900000) + 100000;
		String smsContent = "【饱了么外卖】尊敬的"+phone+"用户，因为条件等原因没达到要求，您的开店审核未通过，请完善后再次申请，非常抱歉。";
		String tmpSmsContent = null;
		try {
			tmpSmsContent = URLEncoder.encode(smsContent, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		String url = Config.BASE_URL + operation;
		String body = "accountSid=" + accountSid + "&to=" + phone + "&smsContent=" + tmpSmsContent
				+ HttpUtil.createCommonParam();

		// 提交请求
		String result = HttpUtil.post(url, body);
		System.out.println("result:" + System.lineSeparator() + result);
		return ""+ran;
	}
}